package com.jason.concurrent.test;

/**
 * @Author  yslai
 * @Date  2022/9/16 16:43
 * @Description 多线程编程的步骤
 * 使用synchronized方法进行同步代码块
 */
class SlTick{


    private int number = 30;

    public synchronized void sale() {
        if (number > 0) {
            System.out.println("票：" + (number--) + "线程:" + Thread.currentThread().getName() + "卖出" + number);
        }
    }

}

public class concurrent {




    public static void main(String[] args) {

        SlTick tick = new SlTick();
        // 创建多个线程
        Thread a1 = new Thread(()->{
            for (int i = 0; i < 40; i++) {
                tick.sale();
            }
        },"aa");

        a1.start();

        Thread bb = new Thread(() -> {
            for (int i = 0; i < 40; i++) {
                tick.sale();
            }
        }, "bb");
        bb.start();

    }
}
class run implements Runnable{

    @Override
    public void run() {

    }
}
